package lasec.util;

import lasec.connect.DBManager;

import org.apache.mahout.math.Matrix;

public class VectorSpaceModel {
	private String uid;
	private DBManager manager;
	private Matrix A;
	private Matrix B;
	private Matrix similar;

	public VectorSpaceModel(String uid) {
		this.uid = uid;

		manager = new DBManager();
		A = manager.create2DMatrix(uid);
		B = manager.createMy2DMatrix(uid);

		similar = B.times(A);
		similar.setColumnLabelBindings(A.getColumnLabelBindings());

		A = null;
		B = null;
		manager = null;
	}

	public Matrix getSimilarUsers() {
		return similar;
	}

	private void displayMatrixContent(String matrixName, Matrix matrix) {
		System.out.println("Matrix name: " + matrixName);
		if (matrix.getRowLabelBindings() != null) {
			System.out.println("Row count: " + matrix.rowSize());
			System.out.println("Row labels: "
					+ matrix.getRowLabelBindings().toString());
		}
		if (matrix.getColumnLabelBindings() != null) {
			System.out.println("Column count: " + matrix.columnSize());
			System.out.println("Column labels: "
					+ matrix.getColumnLabelBindings().toString());
		}
		for (int i = 0; i < matrix.rowSize(); i++) {
			StringBuilder tempStr = new StringBuilder();
			for (int j = 0; j < matrix.columnSize(); j++) {
				tempStr.append(Double.parseDouble(String.format("%.4f",
						matrix.get(i, j)))
						+ ", ");
			}
			System.out.println(tempStr);
			tempStr = null;
		}
	}
}
